USE SAS
GO

IF EXISTS (SELECT 1 from sysobjects where xtype = 'FN' AND NAME = 'GetStatesXml')
	DROP FUNCTION dbo.GetStatesXml
GO


CREATE FUNCTION [dbo].[GetStatesXml] ()
RETURNS VARCHAR(MAX)
AS
BEGIN
	
	declare 
		@states			varchar(max)

	SET @states	= '<STATES><entry id=""></entry>'

	select @states = @states + '<entry id="' + [State] + '"><![CDATA['+StateDesc +']]></entry>' 
	from TR_States order by [State]
	set @states = @states + '</STATES>'


	return @states

END